//
//  CustomPopTableview.m
//  AoJi
//
//  Created by MinwenYi on 15-3-4.
//  Copyright (c) 2015年 xuanheng. All rights reserved.
//

#import "CustomPopTableview.h"
#import "PopTableViewCell.h"
@interface CustomPopTableview()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray *marr;
    UITableView *poptableview;
    
}
@end
@implementation CustomPopTableview


-(instancetype)initWithFram:(CGRect)frame dataArry:(NSArray *)arr
{
   
     self =[super initWithFrame:frame];
    if (self) {
        
        marr=arr;
        [self addPoptableview];
    }
    return self;

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


-(void)addPoptableview
{
    self.backgroundColor=kSemitoumincolor;
    poptableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth, 300) style:UITableViewStylePlain];
    [self addSubview:poptableview];
    [poptableview setDelegate:self];
    [poptableview setDataSource:self];
    poptableview.showsVerticalScrollIndicator=NO;
    poptableview.bounces=NO;
    [poptableview registerClass:[PopTableViewCell class] forCellReuseIdentifier:@"cell"];
    UIImage *shangHuaImg=[UIImage imageNamed:@"shanghua.png"];
    UIImageView *shangHua=[[UIImageView alloc]initWithFrame:CGRectMake(0, viewBottom(poptableview), Mainwidth, shangHuaImg.size.height*Mainwidth/shangHuaImg.size.width)];
    
    shangHua.contentMode=UIViewContentModeScaleAspectFit;
    shangHua.image=shangHuaImg;
    [self addSubview:shangHua];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return marr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    PopTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];

    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    if (indexPath.row==0) {
        cell.titleLabel.text=marr[indexPath.row];
    }else{
    cell.titleLabel.text=[marr[indexPath.row] objectForKey:@"name"];
    }
    cell.titleLabel.textAlignment=NSTextAlignmentCenter;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 35;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if ([self.delegatecu respondsToSelector:@selector(seletRow:)]) {
        [self.delegatecu seletRow:(int)indexPath.row];
    }
}

-(void)reloadViewWithArray:(NSArray*)newAarry
{
    marr=newAarry;
    [poptableview reloadData];
}
@end
